home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
13h_kit
/
getfont.doc
< prev
next >
Wrap
Text File
|
1991-07-04
|
7KB
|
137 lines
>>> GETFONT.DOC
****************************************************************************
Images.Hpp and Images.Cpp along with this document file are copyright 1991
by the Gamers Programming Workshop, GAMERS forum, Compuserve (GO GAMERS,
section 11). The code and related document are free for use, distribution,
and modification, provided the following conditions are met:
1. no commercial use of this source code or documents is permitted.
2. no fee may be charged beyond disk duplication cost for any of this
material.
3. If the code is upgraded or modified a copy of the modification must
be uploaded to section 11 of the GAMERS forum on Compuserve. All
modifications must be documented and the author's name included in
the source code header block, and the subsequent file package must
include all the original doc files as well as any additions.
****************************************************************************
The getfont.cpp program can be used to capture fonts you have designed and
saved as a PCX format file. This is not a polished command line program,
but rather a source code framework which you can modify to get and work
with your own fonts. In it's original form the program is set up to capture
a font from FONT1.PCX and create the file CSFONT1.FNT. This is the font
included with this package. The first step is to create the font as a PCX
file. This can be done with any paint program that works with these files.
The capture program currently supports 3 rows of 32 characters. This allows
you to capture the standard keyboard set. The program could easily be mod-
ified to capture the full 256 character set.
Lay the font out as in the example pcx FONT1.PCX inlcuded in this package.
The characters must be alligned with no whitespace between them, in rows
such that each row has the same number of characters. Use only two colors,
a background color and a foreground color. It does not matter which two you
use. Decide on a character frame size (the sample font is 6 x 6 pixels), and
then allign these frames in rows. Generally the characters will not be as
wide or as tall as the character frame. In the sample font the widest char-
acters (such as 'W') occupy the top left 5 x 5 pixels. The leftover line at
the bottom is used for descenders, and the column on the right is left
empty. You may choose any frame size and allignment that you wish, but keep
the character allignment consistent throughout the font for best results.
When you have the characters drawn, save them as a pcx, and then edit the
source code for getfont as described in the section that follows.
Font file format: bytes description
-----------------------------------------------------
0..7 font name, eight characters
8 width of character frame in pixels
9 height of character frame in pixels
10 y distance from top of character to baseline
11 ascii code of first defined character
12 ascii code of last defined character
13 font foreground color
14..141 128 byte character width table
142..? Cursor mask
The font bitmap itself is stored immediately after the cursor mask. At run-
time the size of the cursor mask is determined by:
header.fram_wid * header.fram_hit
So the cursor mask should always have the same dimensions as the character
frame.
To modify the getfont program to capture your own font, you must revise the
data which is stored in the first 160 or so bytes of the file. The values
which will be written to the first 14 bytes (as described above) are stored
in the following structure (showing the data for the example font):
struct header { // font description structure
char font_name[8]; // font name, no file extension
char fram_wid; // width of character frame in pixels
char fram_hit; // height of character frame in pixels
char base_ofs; // baseline y offset from top
char ascii_first; // number of first character defined
char ascii_last; // number of last character defined
char f_color; // original font foreground color
} HDR={"CSFONT1",6,6,5,0x20,0x7F,15}; // <<-----FILL IN HERE
Once you've set up this data you need to enter the character widths into the
character width table. This table is used to display the characters with
their proportional widths, resulting in much nicer looking text. This is
about the worst part of making a font <g>. Here is the width table from the
example font. The character widths are in ascii ascending order.
char width[128] = {4,2,3,5,5,5,5,2,2,2,2,4,2,2,2,5,4,2,4,4,4,4,4,4,4,
4,2,2,5,4,5,4,5,4,4,4,4,4,4,4,4,3,4,4,4,5,5,4,4,4,
4,4,4,4,4,5,5,4,4,2,5,2,5,5,2,5,4,4,4,4,3,4,4,3,4,
4,2,5,4,4,4,4,4,4,3,4,4,5,4,4,4,2,2,2,4,5};
Next, the cursor mask must be defined. Use 0's for background, and 1's for
foreground. This cursor will be displayed whenever you get user input from
screen using the font class. Here is the cursor from the sample font, which
is a diamond shape:
char cursor_mask[6][6]= {0,0,1,0,0,0,
0,1,0,1,0,0,
1,0,0,0,1,0,
0,1,0,1,0,0,
0,0,1,0,0,0,
0,0,0,0,0,0};
Finally a block of constants which control where on the PCX the program looks
for the font need to be dealt with. These are as follows:
const char x_origin=20; // top left x of first frame in each row
const char row1_y_origin=24; // top left y of first frame in row #1
const char row2_y_origin=31; // row #2, and
const char row3_y_origin=38; // row #3
const char chars_per_row=32; // number of frames in each row
const char pcxfile[80]="FONT1.PCX"; // source pcx file and path
const char fntfile[80]="CSFONT1.FNT"; // destination font file name /path
Now run the program. If all is well you will hear a beep after the program
has finished creating the font file. If the above steps were followed corr-
ectly all you will have to do to use the new font is declare an instance of
it: font new_font("newfont.fnt").
NOTES: This program is rough, in that it has absolutely no user interface.
If you're not a programmer you'll be hard pressed to use it. if you are a
programmer, and want to add a front end, feel free to do so. This is the first
version, and there will likely be many changes.
Support:
Support will be provided for these tools where and as possible through mess-
ages posted to 76605,2346 in the Game Design section (sec. 11) of the Gamers
Forum on Compuserve. Sorry, no telephone support is possible.